<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var reverseString = function (s) {
            if (s.length<=1) return s
            for (let i=0;i<Math.floor(s.length/2);i++){
                let t = s[i]
                s[i] = s[s.length-1-i]
                s[s.length-1-i] = t
            }
            return s
        };
        var reverseStr = function(s, k) {
            let resArr = s.split('')
            if (s.length<=1) return s
            for (let i=0;i<s.length;i+=2*k){
                let l=i-1
                let r=i+k>s.length?s.length:i+k
                while(++l<--r) [resArr[l],resArr[r]]=[resArr[r],resArr[l]]
            }
            return resArr.join('')
        };
        console.log(reverseStr('abcdefg',2))
    </script>
</body>

</html>